package com.red.wood.dubbo.task;

import java.io.Serializable;

import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.red.wood.module.cdn.module.SqlCdnInfo;
import com.red.wood.module.ircs.module.SqlIrcsInfo;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class SqlStatisticsTask implements Serializable{

	private static final long serialVersionUID = 1L;

	private static final Log log = LogFactory.getLog(SqlStatisticsTask.class);
	
	public static void sqlCdntask() {
		XStream xstream = new XStream(new DomDriver());
		xstream.processAnnotations(SqlCdnInfo.class);
		String xml = getXmlInfo("sqlCdnInfo.xml");
		SqlCdnInfo sql = (SqlCdnInfo) xstream.fromXML(xml);
		System.out.println(sql);
	}
	
	public static void sqlIrcstask() {
		XStream xstream = new XStream(new DomDriver());
		xstream.processAnnotations(SqlIrcsInfo.class);
		String xml = getXmlInfo("sqlIrcsInfo.xml");
		SqlIrcsInfo sql = (SqlIrcsInfo) xstream.fromXML(xml);
		System.out.println(sql);
	}
	
	/**
	 * 获取配置文件中的信息
	 * @param day
	 * @param config
	 * @return
	 */
	private static String getXmlInfo(String config) {
		String xml = "";
		try {
			ClassLoader classLoader = SqlStatisticsTask.class.getClassLoader();  
			xml = IOUtils.toString(classLoader.getResourceAsStream("sqlconfig/"+config),"UTF-8");  
		}catch(Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
		}
		return xml;
	}
}
